package com.atom.wifiupload;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.atom.wifiupload.gen.DaoMaster;
import com.atom.wifiupload.gen.DaoSession;

/**
 * ============================================================
 * project: WIFI-Upload
 * package: com.atom.wifiupload
 * fileDescribe:
 * user: admin
 * email: 1299854942@qq.com
 * createTime: 2017/6/23  16:34
 * modify:
 * version:: V1.0
 * ============================================================
 **/
public class WifiBookApp extends Application {


    private static Context instance;

    private static DaoSession daoSession;

    public static Context getsInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        //配置数据库
        setupDatabase();
    }

    /**
     * 配置数据库
     */
    private void setupDatabase() {
        //创建数据库shop.db"
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "file.db", null);
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取Dao对象管理者
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoInstant() {
        return daoSession;
    }
}
